<?php
 require("../include/db.php");
 require("../include/head.php");
?>
<table width="100%">
    <tr>
    	<td width="200" valign="top">
          Administrator option
          <UL>
           <li><a href="allcompanies.php">All companies</a></li>
           <li><a href="report.php">Report</a></li>
          </UL>
   	  </td>   
   	  <td valign="top">
   	  	<form action="report.php" method="post">
   	  	 <h1>Send mail Stat. Report</h1>
   	  	<B>Date rang:</B>
   	  	</BR>
   	  	 From 
      	<SELECT tabIndex=13 name=from_mon>
      		<OPTION value=1>January</OPTION> 
      		<OPTION value=2>February</OPTION>
      		<OPTION value=3>March</OPTION>
      		<OPTION value=4>April</OPTION>
      		<OPTION value=5>May</OPTION>
      		<OPTION value=6>June</OPTION>
      		<OPTION value=7>July</OPTION>
      		<OPTION value=8>August</OPTION>
      		<OPTION value=9>September</OPTION>
      		<OPTION value=10>October</OPTION>
      		<OPTION value=11>November</OPTION>
      		<OPTION value=12>December</OPTION>
      	</SELECT>
      	<SELECT tabIndex=14 name=from_day>
         		<?php
        		for ($i=1;$i<=31;$i++)
        		{
        			print_r("<option value=".($i).">".($i)."</option>\r\n");
        		}
        		?>
        </SELECT>
        <SELECT  tabIndex=15 name=from_yr>
        	<?php
        	$today = getdate();
        	$year = $today[year];
        	for ($i=0;$i<=80;$i++)
        	{
        		print_r("<option value=".($year-$i).">".($year-$i)."</option>\r\n");
        	}
        	?>
       	</SELECT>
   	  	 To
      	<SELECT tabIndex=13 name=to_mon>
      		<OPTION value=1>January</OPTION>
      		<OPTION value=2>February</OPTION>
      		<OPTION value=3>March</OPTION>
      		<OPTION value=4>April</OPTION>
      		<OPTION value=5>May</OPTION>
      		<OPTION value=6>June</OPTION>
      		<OPTION value=7>July</OPTION>
      		<OPTION value=8>August</OPTION>
      		<OPTION value=9>September</OPTION>
      		<OPTION value=10>October</OPTION>
      		<OPTION value=11>November</OPTION>
      		<OPTION value=12>December</OPTION>
        </SELECT>
      	<SELECT tabIndex=14 name=to_day>
         		<?php
        		for ($i=1;$i<=31;$i++)
        		{
        			print_r("<option value=".($i).">".($i)."</option>\r\n");
        		}
        		?>
        </SELECT>
        <SELECT  tabIndex=15 name=to_yr>
        	<?php
        	$today = getdate();
        	$year = $today[year];
        	for ($i=0;$i<=80;$i++)
        	{
        		print_r("<option value=".($year-$i).">".($year-$i)."</option>\r\n");
        	}
        	?>
       	</SELECT>
       	<br>
   	  	</BR>
   	  	</BR>
        <B>cycle choose:</B>
       </BR>
       <?
       $cycle =$_POST["cycle"];
       if ($cycle=="")
       {
       	$cycle="Day";
       }
       ?>
         <input type="radio" name="cycle" value="Day" <?if ($cycle=="Day") echo "checked";?>/>Day
         <input type="radio" name="cycle" value="Week" <?if ($cycle=="Week") echo "checked";?>/>Week
         <input type="radio" name="cycle" value="Month" <?if ($cycle=="Month") echo "checked";?>/>Month
         <input type="radio" name="cycle" value="Year" <?if ($cycle=="Year") echo "checked";?>/>Year
        
        <p>
          <input type="submit" value="Stat.">
        </p>
        <p>&nbsp;  </p>
   	  	</form>
   	  	<table width="200" id="contentTabled">
   	  		<tr>
   	  			<td><b>Senddate</b></td>
   	  			<td><b>send out email count</b></td>
   	  		</tr>
   	  	<?
  			$fromday=date("Y-m-d" , mktime(0,0,0,$_POST["from_day"],$_POST["from_mon"],$_POST["from_yr"]));
  			$today=date("Y-m-d" , mktime(0,0,0,$_POST["to_day"],$_POST["to_mon"],$_POST["to_yr"]));
  			
   	  	$sql="select senddate as senddate,count(*) from mails where senddate between '$fromday' and '$today' group by senddate";
   	  	if ($_POST["cycle"]=="Week")
   	  	{
   	  		$sql="select DAYOFWEEK(senddate) as senddate,count(*) from mails group by DAYOFWEEK(senddate)";
   	  	}
   	  	else if ($_POST["cycle"]=="Month")
   	  	{
   	  		$sql="select MONTH(senddate) as senddate,count(*) from mails group by MONTH(senddate)";
   	  	}
   	  	else if ($_POST["cycle"]=="Year")
   	  	{
   	  		$sql="select YEAR(senddate) as senddate,count(*) from mails group by YEAR(senddate)";
   	  	}
   	  	$conn=getconnection();
   	  	$resultd=mysql_query($sql,$conn);
   	  	while   ($rowd=mysql_fetch_array($resultd))
   	  	{
   	  		echo "<tr>";
   	  		echo "<td>".$rowd["senddate"]."</td>";
   	  		echo "<td>".$rowd[1]."</td>";
   	  		echo "</tr>";
   	  	}
   	  	?>
   	  </table>
   	  </td>   
   	</tr>
</table>
<?php
 include "../include/foot.php";
?>